package com.example.base.checker;

import org.springframework.util.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;

public class IllegalPwdCheckImpl implements ConstraintValidator<IllegalPwdCheck, String> {
    private String pattern;

    @Override
    public void initialize(IllegalPwdCheck constraintAnnotation) {
        pattern = constraintAnnotation.matchReg();
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (StringUtils.isEmpty(value)) {
            return true;
        }
        return Pattern.matches(pattern, value);
    }
}
